/*
 * @Author: liming-pan
 * @Date: 2022-01-29 10:22:20
 * @LastEditors: liming-pan
 */
// import router from './index'
import store from '@/store'
const whiteList = ['/login']

function permission(router) {
  const getToken = () => {
    return store.getters.token
  }
  router.beforeEach((to, from, next) => {
    if (getToken()) {
      if (to.path === '/login') {
        next('/')
      } else {
        next()
      }
    } else {
      if (whiteList.includes(to.path)) {
        next()
      } else {
        next('/login')
      }
    }
  })
}

export default permission
